package com.origin.app.bean;

import android.util.Log;

import androidx.databinding.BaseObservable;
import androidx.databinding.Bindable;

import com.jeremyliao.liveeventbus.core.LiveEvent;
import com.origin.app.utils.NetAppUtils;
import  com.origin.app.utils.TimeUtils;
import com.origin.app.BR;

import java.io.Serializable;
import java.util.Objects;

public class CompanyPointBean extends BaseObservable implements LiveEvent, Serializable {

    private static final long serialVersionUID = 1L;
    /**
     * Company_Code : 007
     * Company_Name : 七组
     * In_Code : 1fb5c0bc48a011efb58052540023a00d
     * Id_Card : 512120200111014838
     * In_Type : 1
     * In_Class : 0
     * Name : 七组人员19
     * TaskId : 2733
     * Supplier : 19
     * Product_Model1 : 19
     * TagId : 9519124592
     * Equipment_Code : 9519124592
     * IccId : 89860317940288075258
     * LocationType : 0
     * WGS84 : {"Lng":103.9695286831054,"Lat":30.632498782640702}
     * GCJ02 : {"Lng":103.9717263,"Lat":30.629815}
     * Address : 四川省成都市武侯区簇锦街道西部智谷A区
     * IsHistory : 0
     * LocationTime : 2024-08-14T16:34:31
     * ReportTime : 2024-08-14T16:34:31.783497+08:00
     * StepCount : 104
     * Battery : 0
     * Heart : -1
     * ActiveAlarm : 0
     * TamperState : 0
     * ChargeState : 0
     * BandState : 0
     * LocationState : 1
     * EquipmentState : 2
     * AlarmType_List : 电子围栏越界
     * NetWork : 4G
     * Acc : 0
     * ExternalData : {
     "signal": "77",
     "signal
     * FWS : 0
     * IsRepair : 0
     * IsWarehous : 1
     */

    public void refreshByLocation(CompanyPointBean companyPointBean){
        NetWork=companyPointBean.network;

        Address=companyPointBean.address;
        LocationState=companyPointBean.locationstate;


        notifyPropertyChanged(BR._all);
    }
    public void refresh(CompanyPointBean companyPointBean){
        Name=companyPointBean.Name;
        Company_Name=companyPointBean.Company_Name;
        Supplier=companyPointBean.Supplier;
        NetWork=companyPointBean.NetWork;
        EquipmentState=companyPointBean.getEquipmentState();
        Equipment_Code=companyPointBean.getEquipment_Code();
        TamperState=companyPointBean.getTamperState();
        BandState=companyPointBean.getBandState();
        Battery=companyPointBean.getBattery();
        LocationTime=companyPointBean.getLocationTime();
        Address=companyPointBean.getAddress();
        TaskId=companyPointBean.getTaskId();
        phone=companyPointBean.getPhone();
        address=companyPointBean.address;

        if(GCJ02==null){
            GCJ02=new GCJ02Bean();
        }

        try {
            GCJ02.Lat=companyPointBean.getGCJ02().Lat;
            GCJ02.Lng=companyPointBean.getGCJ02().Lng;
        }catch (Exception e){

        }

        notifyPropertyChanged(BR._all);
    }
    public  boolean  checkInfoSame(CompanyPointBean companyPointBean){
        if(getEquipmentState()!=companyPointBean.getEquipmentState()){
            return  false;
        }

        if(getGCJ02().Lat!=companyPointBean.getGCJ02().Lat){
            return  false;
        }

        if(getGCJ02().Lng!=companyPointBean.getGCJ02().Lng){
            return  false;
        }

        if(!Objects.equals(getAddress(), companyPointBean.getAddress())){
            return  false;
        }


        return true;
    }

    public void  refreshPic(String _picUrl){
        picUrl= _picUrl;
        notifyPropertyChanged(BR._all);
    }


    private String picUrl;

    public String getPicUrl() {
        return picUrl;
    }

    public void setPicUrl(String picUrl) {
        this.picUrl = picUrl;
    }

    public boolean isCard(){
        return  In_Type == 2;
    }
    private String company_code;
    private String company_name;
    private String in_code;
    private String name;
    private String phone;
    private String photo;

    private String Company_Code;
    private String Company_Name;
    private String In_Code;
    private String Id_Card;
    private int In_Type;
    private int In_Class;
    private String Name;
    private int TaskId;
    private int Supplier;
    private int Product_Model1;
    private String TagId;
    private String Equipment_Code;
    private String IccId;
    private String LocationType;
    private WGS84Bean WGS84;
    private GCJ02Bean GCJ02;
    private String Address;
    private int IsHistory;
    private String LocationTime;
    private String ReportTime;
    private int StepCount;
    private int Battery;
    private int Heart;
    private int ActiveAlarm;
    private int TamperState;
    private int ChargeState;
    private int BandState;
    private int LocationState;
    private int locationstate;
    private int EquipmentState;
    private String AlarmType_List;
    private String NetWork;
    private String network;
    private int Acc;
//    private String ExternalData;
    private int FWS;
    private int IsRepair;
    private int IsWarehous;

    // 心率
    private int vitalsignl;
    //
    private String lng;
    private String lat;

    private String address;

    public String getLng() {
        return lng;
    }

    public void setLng(String lng) {
        this.lng = lng;
    }

    public String getLat() {
        return lat;
    }

    public void setLat(String lat) {
        this.lat = lat;
    }

    public int getVitalsignl() {
        return vitalsignl;
    }

    public void setVitalsignl(int vitalsignl) {
        this.vitalsignl = vitalsignl;
    }

    public String getCompany_code() {
        if(Company_Code!=null&&!Company_Code.isEmpty()){
            return  Company_Code;
        }
        return company_code;
    }

    public void setCompany_code(String company_code) {
        this.company_code = company_code;
    }


    public void setCompany_name(String company_name) {
        this.company_name = company_name;
    }



    public void setIn_code(String in_code) {
        this.in_code = in_code;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getPhoto() {
        return photo;
    }

    public void setPhoto(String photo) {
        this.photo = photo;
    }


    public void setCompany_Code(String Company_Code) {
        this.Company_Code = Company_Code;
    }

    public String getCompany_Name() {
        if(company_name!=null&& !company_name.isEmpty()){
            return  company_name;
        }
        return Company_Name;
    }

    public void setCompany_Name(String Company_Name) {
        this.Company_Name = Company_Name;
    }

    public String getIn_Code() {
        if(In_Code!=null){
            return  In_Code;
        }
        return in_code;
    }

    public void setIn_Code(String In_Code) {
        this.In_Code = In_Code;
    }

    public String getId_Card() {
        return Id_Card;
    }

    public void setId_Card(String Id_Card) {
        this.Id_Card = Id_Card;
    }

    public int getIn_Type() {
        return In_Type;
    }

    public void setIn_Type(int In_Type) {
        this.In_Type = In_Type;
    }

    public int getIn_Class() {
        return In_Class;
    }

    public void setIn_Class(int In_Class) {
        this.In_Class = In_Class;
    }

    @Bindable
    public String getName() {
        if(name!=null){
            return name;
        }
        return Name;
    }

    public void setName(String Name) {
        this.Name = Name;
        notifyPropertyChanged(BR.name);
    }

    public int getTaskId() {
        return TaskId;
    }

    public void setTaskId(int TaskId) {
        this.TaskId = TaskId;
    }

    public int getSupplier() {
        return Supplier;
    }

    public void setSupplier(int Supplier) {
        this.Supplier = Supplier;
    }

    public int getProduct_Model1() {
        return Product_Model1;
    }

    public void setProduct_Model1(int Product_Model1) {
        this.Product_Model1 = Product_Model1;
    }

    public String getTagId() {
        return TagId;
    }

    public void setTagId(String TagId) {
        this.TagId = TagId;
    }

    public String getEquipment_Code() {
        return Equipment_Code;
    }

    public void setEquipment_Code(String Equipment_Code) {
        this.Equipment_Code = Equipment_Code;
    }

    public String getIccId() {
        return IccId;
    }

    public void setIccId(String IccId) {
        this.IccId = IccId;
    }

    public String getLocationType() {
        return LocationType;
    }

    public void setLocationType(String LocationType) {
        this.LocationType = LocationType;
    }

    public WGS84Bean getWGS84() {
        return WGS84;
    }

    public void setWGS84(WGS84Bean WGS84) {
        this.WGS84 = WGS84;
    }

    public GCJ02Bean getGCJ02() {
        return GCJ02;
    }

    public void setGCJ02(GCJ02Bean GCJ02) {
        this.GCJ02 = GCJ02;
    }

    public String getAddress() {
        if(address!=null&& !address.isEmpty()){
            return  address;
        }
        return Address;
    }

    public void setAddress(String Address) {
        this.Address = Address;
    }

    public int getIsHistory() {
        return IsHistory;
    }

    public void setIsHistory(int IsHistory) {
        this.IsHistory = IsHistory;
    }

    public String getLocationTime() {
        return LocationTime;
    }

    public String getLocationTimeFormat() {
        try {
            return  TimeUtils.formatterTime(LocationTime);
        }catch (Exception e){
            return  "";
        }

    }

    public void setLocationTime(String LocationTime) {
        this.LocationTime = LocationTime;
    }

    public String getReportTime() {
        return ReportTime;
    }

    public void setReportTime(String ReportTime) {
        this.ReportTime = ReportTime;
    }

    public int getStepCount() {
        return StepCount;
    }

    public void setStepCount(int StepCount) {
        this.StepCount = StepCount;
    }

    public int getBattery() {
        return Battery;
    }

    public void setBattery(int Battery) {
        this.Battery = Battery;
    }

    public int getHeart() {
        return Heart;
    }

    public void setHeart(int Heart) {
        this.Heart = Heart;
    }

    public int getActiveAlarm() {
        return ActiveAlarm;
    }

    public void setActiveAlarm(int ActiveAlarm) {
        this.ActiveAlarm = ActiveAlarm;
    }

    public int getTamperState() {
        return TamperState;
    }

    public String getTamperStateStr() {
        if (TamperState==0){
            return "正常";
        }
        if (TamperState==1){
            return "拆卸";
        }
        return "未知";
    }


    public void setTamperState(int TamperState) {
        this.TamperState = TamperState;
    }

    public int getChargeState() {
        return ChargeState;
    }

    public void setChargeState(int ChargeState) {
        this.ChargeState = ChargeState;
    }

    public int getBandState() {
        return BandState;
    }

    public String getBandStateStr() {
        if (BandState==0){
            return "正常";
        }
        if (BandState==1){
            return "剪断";
        }
        return  "未知";
    }


    public void setBandState(int BandState) {
        this.BandState = BandState;
    }


    public String getLockStateStr() {
        if(LocationState==0){
            return  "正常";
        }
        if(LocationState==1){
            return  "围栏越界";
        }

        return "禁止进入";
    }

    public int getLocationState() {
        return LocationState;
    }

    public void setLocationState(int LocationState) {
        this.LocationState = LocationState;
    }

    public String getEquipmentStateStr(){
        if(EquipmentState==1){
            return "正常";
        }
        if(EquipmentState==2){
            return "异常";
        }
        return "离线";
    }

    public int getEquipmentState() {
        return EquipmentState;
    }

    public void setEquipmentState(int EquipmentState) {
        this.EquipmentState = EquipmentState;
    }

    public String getAlarmType_List() {
        return AlarmType_List;
    }

    public void setAlarmType_List(String AlarmType_List) {
        this.AlarmType_List = AlarmType_List;
    }

    public String getNetWork() {
        return NetWork;
    }

    public void setNetWork(String NetWork) {
        this.NetWork = NetWork;
    }

    public int getAcc() {
        return Acc;
    }

    public void setAcc(int Acc) {
        this.Acc = Acc;
    }

//    public String getExternalData() {
//        return ExternalData;
//    }
//
//    public void setExternalData(String ExternalData) {
//        this.ExternalData = ExternalData;
//    }

    public int getFWS() {
        return FWS;
    }

    public void setFWS(int FWS) {
        this.FWS = FWS;
    }

    public int getIsRepair() {
        return IsRepair;
    }

    public void setIsRepair(int IsRepair) {
        this.IsRepair = IsRepair;
    }

    public int getIsWarehous() {
        return IsWarehous;
    }

    public void setIsWarehous(int IsWarehous) {
        this.IsWarehous = IsWarehous;
    }

    public static class WGS84Bean {
        /**
         * Lng : 103.9695286831054
         * Lat : 30.632498782640702
         */

        private double Lng;
        private double Lat;

        public double getLng() {
            return Lng;
        }

        public void setLng(double Lng) {
            this.Lng = Lng;
        }

        public double getLat() {
            return Lat;
        }

        public void setLat(double Lat) {
            this.Lat = Lat;
        }
    }

    public static class GCJ02Bean implements Serializable{
        /**
         * Lng : 103.9717263
         * Lat : 30.629815
         */

        private double Lng;
        private double Lat;

        public double getLng() {
            return Lng;
        }

        public void setLng(double Lng) {
            this.Lng = Lng;
        }

        public double getLat() {
            return Lat;
        }

        public void setLat(double Lat) {
            this.Lat = Lat;
        }



    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        CompanyPointBean that = (CompanyPointBean) o;
        return Objects.equals(getCompany_code(), that.getCompany_code());
    }

    @Override
    public int hashCode() {
        return Objects.hash(this.getCompany_code());
    }
}
